package com.njym.java.security.app.biz;

import com.github.pagehelper.PageHelper;
import com.njym.java.annotation.Cache;
import com.njym.java.security.app.entity.CirclePost;
import com.njym.java.security.app.mapper.CirclePostMapper;
import com.njym.java.security.common.biz.BaseBiz;
import com.njym.java.security.common.util.SensitivewordFilter;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 
 *
 * @author lijie
 * @email 717057076@qq.com
 * @date 2019-11-07 14:35:47
 */
@Service
public class CirclePostBiz extends BaseBiz<CirclePostMapper, CirclePost> {

	@Override
	public void insertSelective(CirclePost circlePost){
		//过滤敏感词 标题
		SensitivewordFilter filter = new SensitivewordFilter();
//		Set<String> settitle = filter.getSensitiveWord(circlePost.getSubject(), 1);
		String titlenewStr = filter.replaceSensitiveWord(circlePost.getSubject(), 2, "*");
		//过滤敏感词 内容
//		Set<String> set = filter.getSensitiveWord(circlePost.getMessage(), 1);
		String newStr = filter.replaceSensitiveWord(circlePost.getMessage(), 2, "*");
		circlePost.setSubject(titlenewStr);
		circlePost.setMessage(newStr);
		super.insertSelective(circlePost);
	}

	@Override
	public CirclePost selectById(Object id) {
		mapper.addRead(Integer.parseInt(id.toString()));
		return super.selectById(id);
	}

	@Cache(key = "CirclePostList:{1}",expire = 1)
	public List<CirclePost> getListByCircleId(String groupId,Integer ircleId,Integer status){
		Example example = new Example(CirclePost.class);
		example.createCriteria().andEqualTo("fid",ircleId).andEqualTo("statuses", status).andEqualTo("deleted",0).andEqualTo("invisible",1);
		example.orderBy("dateline").desc();
		return selectByExample(example);
	}

    public void addLike(Integer id){
	    mapper.addLike(id);
    }

	public void addComment(Integer id){
		mapper.addComment(id);
	}

	public List<CirclePost> toExamine(Integer userId){
		return mapper.toExamine(userId);
	}

	public List<CirclePost> release(Integer userId){
		return mapper.release(userId);
	}
}